package com.ruoyi.web.controller.system;

import com.ruoyi.system.domain.HospitalCampus;
import com.ruoyi.system.domain.Result;
import com.ruoyi.system.service.HospitalCampusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/system/hospitalCampus")
public class HospitalCampusController {
    @Autowired
    private HospitalCampusService campusService;

    @PostMapping("/save")
    public int save(@RequestBody HospitalCampus campus) {
        return campusService.save(campus);
    }

    @PutMapping("/update")
    public int update(@RequestBody HospitalCampus campus) {
        return campusService.update(campus);
    }

    @DeleteMapping("/delete/{id}")
    public int delete(@PathVariable Long id) {
        return campusService.delete(id);
    }

    // 获取院区详情（包含联系电话）
    @GetMapping("/{id}")
    public Result<HospitalCampus> selectById(@PathVariable Long id) {
        HospitalCampus campus = campusService.selectById(id);
        return Result.success(campus);
    }

    @GetMapping("/list")

    public Result list(@RequestParam(defaultValue = "1") int pageNum,
                       @RequestParam(defaultValue = "10") int pageSize,
                       String campusName) {
        startPage();
        List<HospitalCampus> list = campusService.selectAllWithContactsAndNavigations(campusName);
        return Result.success(list);
    }

    //根据院区名称获取院区id
    @GetMapping("/getIdByName/{campusName}")
    public int getIdByName(@PathVariable String campusName) {
        return campusService.selectIdByName(campusName);
    }
}